package character;

import config.Config;
import sprite.Transform;
import world.Background;

import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;

public abstract class GameObject{
	private Transform _transform;
	private double _z;

	private Shape _collideBox;
	
	private int _colliderX = 0;
	private int _colliderY = 0;
	private int _colliderXscale = 0;
	private int _colliderYscale = 0;
	
	public GameObject(Transform trans,
                      int hurtx, int hurty, int hurtscale_x, int hurtscale_y){
		_transform = trans;
		this.setCollider(hurtx, hurty, hurtscale_x, hurtscale_y);
	}

	public void setPosition(double x, double y){
		move(-getX(),-getZ());//移动到原点
		move(x,y);
	}
	public Transform getTransform(){
		return _transform;
	}
	

	public void move(double x,double y){
		_z += y;
		_transform.translate(x,y);
	}


	public Shape getHurtBox(){
		AffineTransform as = new AffineTransform();
		as.setTransform(_transform.getTransform());
		_collideBox = as.createTransformedShape(new Rectangle(_colliderX,_colliderY,_colliderXscale,
															_colliderYscale));
		return _collideBox;
	}
	

	public void setCollider(int x1,int y1, int x2, int y2){
		_colliderX = x1;
		_colliderY = y1;
		_colliderXscale = x2;
		_colliderYscale = y2;
	}

	public abstract void update(Graphics2D g);

	public double getZ(){
		return _z;
	}
	public void setZ(double z){
		_z = z;
	}
	public double getX(){
		return _transform.getX();
	}
	public double getY(){
		return  _transform.getY();
	}
}
